﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using NumericalData.Systems;
using NumericalData.Reflection;
using NumericalData.SolvationMethods.Async;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPFSolution.UserControls
{
    /// <summary>
    /// Interaction logic for AsyncTraceableIterationMethodComboBox.xaml
    /// </summary>
    public partial class AsyncTraceableIterationMethodComboBox : UserControl
    {
        private Dictionary<string, IAsyncSolvable<DiagnosticsAnswer>> dict;

        public static readonly DependencyProperty SelectedMethodProperty =
            DependencyProperty.Register("SelectedMethod", typeof (IAsyncSolvable<DiagnosticsAnswer>), typeof (AsyncTraceableIterationMethodComboBox), new PropertyMetadata(default(IAsyncSolvable<DiagnosticsAnswer>)));

        public IAsyncSolvable<DiagnosticsAnswer> SelectedMethod
        {
            get { return (IAsyncSolvable<DiagnosticsAnswer>) GetValue(SelectedMethodProperty); }
            private set { SetValue(SelectedMethodProperty, value); }
        }

        public AsyncTraceableIterationMethodComboBox()
        {
            InitializeComponent();
            dict = SolvationMethodsReflection.GetAsyncableTraceableIterationMethodsDictionary();
            InitializeComboBox();
        }

        private void InitializeComboBox()
        {
            foreach (KeyValuePair<string, IAsyncSolvable<DiagnosticsAnswer>> pair in dict)
            {
                MethodsBox.Items.Add(new ListBoxItem {Content = pair.Key});
            }
            
        }

        private void MethodsBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var methName = ((ListBoxItem) MethodsBox.SelectedItem).Content.ToString();
            SelectedMethod = dict[methName];
        }

    }
}
